#ifndef MESHSUBDIVIDE_SRC_RENDERER_H
#define MESHSUBDIVIDE_SRC_RENDERER_H

#include <Base.h>
#include <JsonEX.h>
#include <osg/Switch>
#include <osg/MatrixTransform>
#include <osgViewer/Viewer>
#include <osgGA/GUIEventHandler>

#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/DefaultTriMesh.hh>

class Renderer : public Reference
{
public:
    Renderer();

    void ReadModel(const std::string& filename);

    void Home();

    void Run();

    void Reset();

    void SetSubdivide(int);

    void ShowHelp(bool);

private:
    ~Renderer() override;

    void initialize();

    void release();

    void initHelp();

    void setGeometry(osg::Group*, OpenMesh::TriMesh&);

    void test_open_mesh();

    osg::ref_ptr<osg::Switch>          _root;
    osg::ref_ptr<osg::Group>           _scene;
    osg::ref_ptr<osg::Group>           _helpGroup;
    osg::ref_ptr<osgViewer::Viewer>    _viewer;

    OpenMesh::TriMesh _mesh;
    OpenMesh::TriMesh _originMesh;
};

class MyGUIEventHandler : public osgGA::GUIEventHandler
{
public:
    explicit MyGUIEventHandler(Renderer*);
    ~MyGUIEventHandler() override;

    bool handle(const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) override;

private:
    RefPtr<Renderer> _renderer;
};


#endif // MESHSUBDIVIDE_SRC_RENDERER_H
